package com.mightybird.designpattern.creational.prototype.deepclone;

import java.io.*;

public class CustomerD implements Serializable {
    private String name;
    private AddressD address;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public AddressD getAddress() {
        return address;
    }

    public void setAddress(AddressD address) {
        this.address = address;
    }

    public CustomerD deepClone() throws IOException, ClassNotFoundException {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        ObjectOutputStream objectOutputStream = new ObjectOutputStream(byteArrayOutputStream);
        objectOutputStream.writeObject(this);
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayOutputStream.toByteArray());
        ObjectInputStream objectInputStream = new ObjectInputStream(byteArrayInputStream);
        return (CustomerD) objectInputStream.readObject();
    }
}
